// 덧글정보를 가져온다.
function fnLoadComment(strAtcNo, strUserId) {
	var strUrl = "/board/comment/list/ATC_NO/" + strAtcNo;
	var strParam = "";
	
	$("#id_textarea_comment").val("");
	$("#id_loading_comment").show();
	$("#id_tbl_save_comment .dynamic_row").remove();
	
	$.ajax({
		type: "get",
		url: strUrl,
		data: strParam,
		success: function(jsonData) {
			var strHtml = "";
			if (jsonData.length == 0) {
				strHtml += "<tr class='dynamic_row'><td colspan='3'>" + msg_board_BoardCommentAjax_1 + "</td></tr>";
			} else {
				$.each(jsonData, function(i) {
					var objRegDate = new Date();
					objRegDate.setTime(jsonData[i].regYmdt);
					var strRegDate = objRegDate.getFullYear() + "." + 
							( ((objRegDate.getMonth()+1)<10) ? ("0"+(objRegDate.getMonth()+1)) : (objRegDate.getMonth()+1) ) + "." + 
							( (objRegDate.getDate()<10) ? ("0"+objRegDate.getDate()) : (objRegDate.getDate()) ) + " " + 
							( (objRegDate.getHours()<10) ? ("0"+objRegDate.getHours()) : (objRegDate.getHours()) ) + ":" + 
							( (objRegDate.getMinutes()<10) ? ("0"+objRegDate.getMinutes()) : (objRegDate.getMinutes()) ) + ":" + 
							( (objRegDate.getSeconds()<10) ? ("0"+objRegDate.getSeconds()) : (objRegDate.getSeconds()) );
					
					strHtml += "<tr class='dynamic_row'>";
					strHtml += "<td style='text-align:left;'><b>" + jsonData[i].regrEmpNm + "</b></td>";
					strHtml += "<td style='text-align:left;'>" + jsonData[i].cmtCont + "&nbsp;&nbsp;&nbsp;&nbsp;<span class='light'>" + strRegDate + "</span></td>";	
					
					if (strUserId == jsonData[i].regrEmpNo) {
						strHtml += "<td><input type='image' src='http://static.naver.com/groupware/2010/btn_pop_close.gif' onClick='fnRemoveComment(\"" + strAtcNo + "\",\"" + jsonData[i].cmtSeq + "\",\"" + strUserId + "\")'></td>";		
					} else {
						strHtml += "<td>&nbsp;</td>";	
					}
					
					strHtml += "</tr>";	
				});							
			}
			$("#id_loading_comment").hide();
			$("#id_tbl_save_comment tr:first").after(strHtml);
		},
		error: function(xhr, info) {
			alert(msg_basic_AjaxError_1.replace("$0", xhr.status).replace("$1", info));
		}
	});
}



// 덧글을 입력한다.
function fnSaveComment(strAtcNo, strUserId) {
	var strCmt = $("#id_textarea_comment").val();
	if (strCmt == "") {
		alert(msg_board_BoardCommentAjax_2);
		return;
	}
	
	var strUrl = "/board/comment/add/ATC_NO/" + strAtcNo;
	var strParam = "cmtCont=" + strCmt;
	
	$.ajax({
		type: "post",
		url: strUrl,
		data: strParam,
		success: function(msg) {
			if (msg == "SUCCESS") {
				fnLoadComment(strAtcNo, strUserId);
			} else {
				alert(msg_board_BoardCommentAjax_3);
			}
		},
		error: function(xhr, info) {
			alert(msg_basic_AjaxError_1.replace("$0", xhr.status).replace("$1", info));
		}
	});	
}



// 덧글을 삭제한다.
function fnRemoveComment(strAtcNo, strCmtSeq, strUserId) {
	if (confirm(msg_board_BoardCommentAjax_4)) {		
		var strUrl = "/board/comment/remove/ATC_NO/" + strAtcNo + "/CMT_SEQ/" + strCmtSeq;
		var strParam = "";
		
		$.ajax({
			type: "get",
			url: strUrl,
			data: strParam,
			success: function(msg) {
				if (msg == "SUCCESS") {
					fnLoadComment(strAtcNo, strUserId);
				} else {
					alert(msg_board_BoardCommentAjax_5);
				}
			},
			error: function(xhr, info) {
				alert(msg_basic_AjaxError_1.replace("$0", xhr.status).replace("$1", info));
			}
		});
	}
}

















